package com.app.configuration.web.exception;
import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;

import com.app.util.common.HandlerResult;
import com.app.util.common.RequestUtil;
import com.app.util.common.ResponseUtil;






//@ControllerAdvice用于拦截Controller的接口，比如当接口抛出异常时，可以被拦截，然后返回指定的报文
@ControllerAdvice(basePackages="com.suncnpap")
public class GlobaWebException {

	@ExceptionHandler(RuntimeException.class)
	public void exceptionHandler(HttpServletRequest request ,HttpServletResponse response,Exception e) {
		
		HandlerResult result = new HandlerResult();
		
//		 if(RequestUtil.isAjax(request)){
//         	Map<String,Object> map = new HashMap<String,Object>();
//         	map.put("globa_nopermission", "-1");
//         	map.put("tip","<font color='red'><b></b></font>");
//         	ResponseUtil.writeJson(map, response);
//         	return null;
         	
         	result.setCode(1);
         	result.setMessage("系统访问出异常");
//         }
		 
		 
		 ResponseUtil.writeJson(result, response);
	}
}
